Skip to content

Glasgow | Jan-26 | Elisabeth Matulian | Sprint 2 | Coursework#959

Open
Elisabeth-Matulian wants to merge 5 commits intoCodeYourFuture:mainfrom
Elisabeth-Matulian:coursework/sprint-2
Open

Glasgow | Jan-26 | Elisabeth Matulian | Sprint 2 | Coursework#959
Elisabeth-Matulian wants to merge 5 commits intoCodeYourFuture:mainfrom
Elisabeth-Matulian:coursework/sprint-2

Conversation

@Elisabeth-Matulian
Copy link

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Changelist

Completed all exercises

Questions

No questions

@Elisabeth-Matulian Elisabeth-Matulian added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Feb 11, 2026

// c) What is the return value of pad is called for the first time?
// =============> write your answer here
// =============> 00
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To more precisely express a value is a string, we can enclose the value by a pair of double quotes. For example, "00".


function formatAs12HourClock(time) {
const hours = Number(time.slice(0, 2));
const mins = time.slice(3, 5);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could also use time.slice(-2) to extract two characters from the right (or last two characters).

return `${hours - 12}:${mins} pm`;
}
else if (hours == 0) {
return `${hours + 12}:${mins} am`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 +12 is 12. Why not just write 12 directly?

Comment on lines 8 to +10
if (hours > 12) {
return `${hours - 12}:00 pm`;
return `${hours - 12}:${mins} pm`;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If "01:00" is converted to "01:00 am", it is probably reasonable for the caller to expect "13:00" to be converted to "01:00 pm".

When the returned values are not formatted consistently, it may result in unintended side-effect. For examples,

  1. When the strings are displayed, "01:00 pm" and "1:00 pm" would not align as nicely.
01:00 am
1:00 pm
12:00 am
01:00 pm
  1. When the formatted strings are compared in the program, "1:00 pm" < "11:00 pm" and 01:00 am" < "11:00 am" produce different results.

Consistency is important so the caller can be certain what to expect from a function.

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Feb 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Reviewed Volunteer to add when completing a review with trainee action still to take.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments